/** 
 * 文 件 名:SportManageLogic.java
 * Copyright (C) 2007-2012:杭州希禾信息技术有限公司 版权所有 
 * 创 建 人:刘绍辉
 * 日    期:2012-3-12 下午3:36:17
 * 修 改 人: 
 * 日   期:
 * 修改描述:
 * 描   述:TODO
 */
package net.seehealth.healthpad.business.loginmanage;

import java.io.IOException;
import java.util.ArrayList;

import net.seehealth.healthpad.Constants;
import net.seehealth.healthpad.application.base.BaseLogic;
import net.seehealth.healthpad.application.base.BaseModel;
import net.seehealth.healthpad.business.loginmanage.service.ILoginManageLogic;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

/**
 * @className LoginManageLogic
 * @author 刘绍辉
 * @description TODO 验证登录
 * @date 2012-3-12 下午5:22:54
 */
public class LoginManageLogic extends BaseLogic implements ILoginManageLogic {

	public boolean validateLoginInfo(String linkaddr, String port,
			String userName, String password) {
		boolean bool = false;
		bool = this.validateLogin(linkaddr, port, userName, password);
		return bool;
	}

	private boolean validateLogin(String linkaddr, String port, String userName,
			String password) {
		SoapObject soapObject = new SoapObject(
				Constants.Common.LOGINNAMESPACE,
				Constants.Common.LOGIN);
		soapObject.addProperty("linkaddr", linkaddr);
		soapObject.addProperty("port", port);
		soapObject.addProperty("userName", userName);
		soapObject.addProperty("password", password);
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE httpTransport = new HttpTransportSE(
				Constants.Common.LOGINWSDL);
		try {
			httpTransport.call(Constants.Common.LOGINNAMESPACE
					+ Constants.Common.LOGIN, envelope);
			SoapObject result = (SoapObject) envelope.getResponse();
			int count = result.getPropertyCount();
			if (count != 0) {
				String resStr = (String) result.getProperty(0);
				if(resStr!=null&&resStr.endsWith("登录成功")){
					return true;
				}
			}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public BaseModel queryDataByUserId(int userId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public BaseModel queryDataById(int pk) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean addData(BaseModel model) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean modifData(BaseModel model) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean modifData(ArrayList<BaseModel> datas) {
		// TODO Auto-generated method stub
		return false;
	}
	
}
